//
//  LCLoginViewController.m
//  CarCare
//
//  Created by ileo on 15/5/17.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "LCLoginViewController.h"
#import "UserHelper.h"

@interface LCLoginViewController ()

@property (nonatomic, strong) UITextField *telTextField;
@property (nonatomic, strong) UITextField *pwdTextField;

@property (nonatomic, strong) UIButton *okButton;

@end

@implementation LCLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"乐乘登录";
    self.view.backgroundColor = COLOR_HEXSTRING(@"#F6F6F9");
    
    __weak __typeof(self) wself = self;
    [self navSetupLeftTitle:@"取消" action:^{
        [wself dismissViewControllerAnimated:YES completion:nil success:NO info:nil];
    }];
    
    // 输入号码
    self.telTextField = [self textFieldWithFrame:FactoryRectDefault(14) type:TEXTFIELD_TEL];
    [[[UIView viewWithFrame:CGRectMake(0, self.telTextField.top,__MAIN_WIDTH, 0.5 * __MAIN_RATIO_H_667)] resetBackgroundColor:COLOR_HEXSTRING(@"#DCDCDC")] setupOnView:self.view];
    
    
    // 输入密码
    self.pwdTextField = [self textFieldWithFrame:FactoryRectDefault(self.telTextField.bottom + GAP_HEIGHT) type:TEXTFIELD_PWD];
    [[[UIView viewWithFrame:CGRectMake(22 * __MAIN_RATIO_H_667, self.pwdTextField.top, __MAIN_WIDTH - 44 * __MAIN_RATIO_H_667, 0.5 * __MAIN_RATIO_H_667)] resetBackgroundColor:COLOR_HEXSTRING(@"#DCDCDC")] setupOnView:self.view];
    [[[UIView viewWithFrame:CGRectMake(0, self.pwdTextField.bottom , __MAIN_WIDTH, 0.5 * __MAIN_RATIO_H_667)] resetBackgroundColor:COLOR_HEXSTRING(@"#DCDCDC")] setupOnView:self.view];
    
    [ViewFactory addButtonType:BUTTON_EYE onTextField:self.pwdTextField inView:self.view action:nil ok:nil];
    
    
    // 登录按钮
    self.okButton = [ViewFactory normalButtonWithFrame:FactoryRectButtonDefault(self.pwdTextField.bottom + 30 * __MAIN_RATIO_H_667) title:@"乐乘登录" inView:self.view action:^{
        [wself clickOnOK];
    }];
    
    
    
    
    // Do any additional setup after loading the view.
}
- (NSInteger)textFieldMaxNumberWithTextField:(UITextField *)textField
{
    if (textField == self.telTextField) {
        return 10;
    }
    else if (textField == self.pwdTextField)
    {
        return 19;
    }
    else{
        return [super textFieldMaxNumberWithTextField:textField];
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)clickOnOK{
    __weak __typeof(self) wself = self;
    if ([Check isTel:self.telTextField.text]) {
        [UserHelper loginByLCWithTel:self.telTextField.text pwd:self.pwdTextField.text success:^{
            [wself dismissViewControllerAnimated:YES completion:nil success:YES info:nil];
        } fail:^{
            
        }];
    }
}

-(void)textFieldTextHasNull:(BOOL)null{
    self.okButton.enabled = !null;
}

-(void)clickOnKeyBoardDone{
    [self clickOnOK];
}

@end
